﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;

public partial class Provider : System.Web.UI.Page
{
    private DateTime[] SpecialDays = new DateTime[] { new DateTime(2013, 3, 14), new DateTime(2013, 3, 13) };
    protected void Page_Init(object sender, EventArgs e)
    {


    }

    protected void Page_Load(object sender, EventArgs e)
    {
        //PatientsScheduler.VisibleRangeEnd 
    }

    protected void PatientsScheduler_ResourceHeaderCreated(object sender, ResourceHeaderCreatedEventArgs e)
    {
        Panel ResourceImageWrapper = e.Container.FindControl("ResourceImageWrapper") as Panel;
        ResourceImageWrapper.CssClass = "Resource" + e.Container.Resource.Key.ToString();

        Image img = e.Container.FindControl("DoctorImage") as Image;
        img.ImageUrl = "App_Themes/Default/Images/carvalho.png";
        //"Img/" + e.Container.Resource.Text.Split(' ')[1].ToLower() + ".png";
    }

    protected void GroupingDirectionComboBox_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
    {
        UpdateScheduler();
    }

    private void UpdateScheduler()
    {
        PatientsScheduler.GroupingDirection =
            (GroupingDirection)Enum.Parse(typeof(GroupingDirection), GroupingDirectionComboBox.SelectedValue);

        PatientsScheduler.Rebind();
    }
    protected void PatientsScheduler_AppointmentCreated(object sender, AppointmentCreatedEventArgs e)
    {
        Resource doctorAppointment = e.Appointment.Resources.GetResourceByType("DoctorAppointment");
        if (doctorAppointment != null)
        {
            e.Appointment.ToolTip = string.Format("ملاقات با دکتر  {0} در {1}.", doctorAppointment.Attributes["DoctorName"], doctorAppointment.Attributes["RoomName"]);

            Label doctorLabel = (Label)e.Container.FindControl("Doctor");
            doctorLabel.Text = "دکتر " + doctorAppointment.Text;
        }
    }

    protected void PatientsScheduler_AppointmentDataBound(object sender, SchedulerEventArgs e)
    {
        //e.Appointment.ToolTip = string.Format("{0}:\n {1}\n{2}" ,e.Appointment.Subject ,e.Appointment.Resources[0].Text,e.Appointment.Resources[1].Text);
        foreach (DateTime dt in SpecialDays)
        {
            if ((DateTime.Compare(e.Appointment.Start.Date, dt) == 0) || (DateTime.Compare(e.Appointment.End.Date, dt) == 0))
            {
                e.Appointment.AllowDelete = false;
                e.Appointment.AllowEdit = false;
            }
        }
    }
    protected void PatientsScheduler_TimeSlotCreated(object sender, TimeSlotCreatedEventArgs e)
    {
        //RadScheduler scheduler = (RadScheduler)sender;
        //if (scheduler.SelectedView == SchedulerViewType.DayView)
        //{
        //    if (e.TimeSlot.Start.Hour >= 9 && e.TimeSlot.Start.Hour < 13)
        //    {
        //        e.TimeSlot.CssClass = "Enabled";
        //    }
        //    else
        //    {
        //        e.TimeSlot.CssClass = "Disabled";
        //    }
        //}
    }
    protected void PatientsScheduler_AppointmentInsert(object sender, AppointmentInsertEventArgs e)
    {

    }
}
/*protected void RadScheduler1_AppointmentCreated(object sender, AppointmentCreatedEventArgs e)
          {
               Label recurrenceIcon = (Label) e.Container.FindControl("RecurrenceIcon");
               if (e.Appointment.RecurrenceState != RecurrenceState.NotRecurring)
               {
                    if (e.Appointment.RecurrenceState == RecurrenceState.Exception)
                    {
                         recurrenceIcon.CssClass = "rsAptRecurrenceException";
                    }
                    else
                    {
                         recurrenceIcon.CssClass = "rsAptRecurrence";
                    }
               }
               else
               {
                    recurrenceIcon.Visible = false;
               }
 
               Resource teacher = e.Appointment.Resources.GetResourceByType("Teacher");
               if (teacher != null)
               {
                    e.Appointment.ToolTip = string.Format("You can reach {0} at {1}.", teacher.Text, teacher.Attributes["Phone"]);
 
                    Label teacherLabel = (Label) e.Container.FindControl("Teacher");
                    teacherLabel.Text = "Teacher: " + teacher.Text;
               }
 
               Label students = (Label) e.Container.FindControl("Students");
               int studentsCount = 0;
               foreach (Resource student in e.Appointment.Resources.GetResourcesByType("Student"))
               {
                    studentsCount++;
               }
 
               students.Text = studentsCount.ToString() + " student(s)";
          }
     }*/